'use strict';

angular.module('WDCC').controller('MainCtrl', function($scope, $location, $rootScope, $cookieStore,toastr,$http,$anchorScroll) {
	$scope.PublicHead = "html/Public/PublicHead.html";
	$scope.PublicLeft = "html/Public/PublicLeft.html";
	$scope.Home=function(){
		//$scope.SubUrl="html/Welcom.html";
		$scope.SubUrl = "html/RegionDataStatisticsMgmt/index.html";
		$anchorScroll();
	}
	/*
	$scope.QueryWelcomTrans = function(){
		$http.post($rootScope.app.ath + 'WelcomeTrans.json').success(function(res){
			if(res.returnCode=="000010" || res.returnCode=="000003"){
				$location.path('/');
				toastr.error(res.exceptionMessage);
			}else if(res.returnCode=="000000"){
				$rootScope.UserBean.DoctorInfo =  res.DoctorInfo;
				var random = Math.random();
				//$scope.SubUrl = "html/Welcom.html?"+random;
				$scope.MenuClick($rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[0].AuthorityList[0]);
				setTimeout(function(){ 
					$("#"+$rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[0].RoleAuthoritySeq).addClass("in");
				}, 0);
			}else{
				toastr.error(res.exceptionMessage);
			}
		});
	}
	
	$scope.QueryWelcomTrans();*/
	

	//菜单 点击事件
/*	$scope.MenuClick=function(v){
		var random = Math.random();
		$scope.SubUrl="html/"+v.RoleAuthorityName+"/index.html?"+random;
		$scope.MenuClass(v);
	}*/
    $scope.MenuClass = function(val){
		
		setTimeout(function(){
			
			for(var i = 0 ; i < $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList.length; i++){
				
				for(var j = 0 ; j < $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[i].AuthorityList.length; j++){
					var v = $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[i].AuthorityList[j].RoleAuthorityName;
					var v1 = $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[i].AuthorityList[j].RoleAuthoritySeq;
					$("#"+v).removeClass("activein");
					$("#"+v1).removeClass("li_div");
				}
				
			}
			var valName = "#"+val.RoleAuthorityName;
			var valName1 = "#"+val.RoleAuthoritySeq;
		    $(valName).addClass("activein");
		    $(valName1).addClass("li_div");
		}, 0);
		
	}
	//修改个人信息
	$scope.UpdatePersonalInfo={};
	$scope.QueryPersonalInfo = function(){
		$scope.UpdatePersonalInfo=$rootScope.UserBean.DoctorInfo;
		var random = Math.random();
		$scope.SubUrl = "html/UpdatePersonalInfo.html?"+random;
		setTimeout(function(){
			for(var i = 0 ; i < $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList.length; i++){
				
				for(var j = 0 ; j < $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[i].AuthorityList.length; j++){
					var v = $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[i].AuthorityList[j].RoleAuthorityName;
					var v1 = $rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[i].AuthorityList[j].RoleAuthoritySeq;
					$("#"+v).removeClass("activein");
					$("#"+v1).removeClass("li_div");
				}
				
			}
		}, 0);
		$anchorScroll();
	}
	$scope.UpdatePersonalInfoConfirm = function(){
		$http.post($rootScope.app.ath + 'UpdatePersonalInfoTrans.json',$scope.UpdatePersonalInfo).success(function(res){
			if(res.returnCode=="000010" || res.returnCode=="000003"){
				$location.path('/');
				toastr.error(res.exceptionMessage);
			}else if(res.returnCode=="000000"){
				$scope.UpdatePersonalInfo={};
				toastr.success("修改成功，请再次登录");
				$location.path('/');
			}else{
				toastr.error(res.exceptionMessage);
			}
		});
	}
	//退出登录
	$scope.OutLogin = function(){
		$http.post($rootScope.app.ath + 'OutLoginTrans.json').success(function(res){
			if(res.returnCode=="000010" || res.returnCode=="000003"){
				$location.path('/');
				toastr.success("已退出");
			}else if(res.returnCode=="000000"){
				toastr.success("已退出");
				$location.path('/');
			}else{
				toastr.success("已退出");
			}
		});
	}
	
	//回到首页
	$scope.GoToWelcome = function(){
		$scope.QueryWelcomTrans();
		$scope.MenuClass($rootScope.UserBean.DoctorInfo.AdminRoleAuthorityInfoList[0].AuthorityList[0]);
	}
});